// miniprogram/pages/record/detail.js
Page({
  data: {
    record: {}
  },

  onLoad(options) {
    const id = options.id
    this.loadRecordDetail(id)
  },

  loadRecordDetail(id) {
    // 模拟数据
    const records = {
      1: { 
        id: 1, 
        ruleName: '完成家务', 
        points: 10, 
        description: '打扫客厅和厨房', 
        status: 'approved', 
        createdAt: '2023-05-15 18:30',
        auditTime: '2023-05-15 19:00',
        auditor: '张三'
      },
      2: { 
        id: 2, 
        ruleName: '运动健身', 
        points: 15, 
        description: '跑步30分钟', 
        status: 'pending', 
        createdAt: '2023-05-15 19:00' 
      },
      3: { 
        id: 3, 
        ruleName: '迟到', 
        points: -5, 
        description: '今天上班迟到了10分钟', 
        status: 'rejected', 
        createdAt: '2023-05-14 09:10',
        auditTime: '2023-05-14 10:00',
        auditor: '李四',
        auditComment: '请准时上班，避免影响工作'
      },
      4: { 
        id: 4, 
        ruleName: '早睡早起', 
        points: 5, 
        description: '昨晚10点睡觉，今早6点起床', 
        status: 'approved', 
        createdAt: '2023-05-14 07:00',
        auditTime: '2023-05-14 08:00',
        auditor: '王五'
      }
    }
    
    this.setData({ 
      record: records[id] || {} 
    })
  },

  editRecord() {
    wx.navigateTo({
      url: `/pages/record/add?id=${this.data.record.id}`
    })
  },

  deleteRecord() {
    wx.showModal({
      title: '确认删除',
      content: '确定要删除这条积分记录吗？',
      success: (res) => {
        if (res.confirm) {
          // 实际开发中这里会调用删除接口
          wx.showToast({
            title: '删除成功',
            icon: 'success'
          })
          
          // 返回上一页
          wx.navigateBack()
        }
      }
    })
  }
})